#include "../../Demo/Server.hpp"

void OnConnected(const PtrConnection& conn)
{
    DBG_LOG("new connection : %p", conn.get());
}

void OnMessage(const PtrConnection& conn, Buffer* buf)
{
    DBG_LOG("%s", buf->ReadPostion());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "Hello World";
    conn->Send(str.c_str(), str.size());
}

void OnClosed(const PtrConnection& conn)
{
    DBG_LOG("close connection : %p", conn.get());
}
int main()
{
    TcpServer server(8080);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(5);
    server.SetClosedCallback(OnClosed);
    server.SetConnectedCallback(OnConnected);
    server.SetMessageCallback(OnMessage);
    server.Start();
    return 0;
}